#include <bits/stdc++.h>

using namespace std;

class Solution {
public:
    vector<int> topKFrequent(vector<int>& nums, int k) {
		unordered_map<int, int> aux;
		for (int num : nums) aux[num]++;
		auto cmp = [](pair<int, int>& o1, pair<int, int>& o2) { return o1.second > o2.second; };
		priority_queue pQueue(cmp, vector<pair<int, int>> {});

		for (auto& [num, cnt]: aux) {
			if (pQueue.size() == k) {
				if (pQueue.top().second < cnt) {

					pQueue.pop();
					pQueue.emplace(num, cnt);
				}
			} else
				pQueue.emplace(num, cnt);
		}

		vector<int> res;
		while (!pQueue.empty()) {
			res.emplace_back(pQueue.top().first);
			pQueue.pop();
		}
		return res;
	}
private:
};

int main()
{
	Solution solution;
	return 0;
}
